import { Controller, Post, UseGuards, UseInterceptors, UploadedFile, UploadedFiles } from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { JwtAuthGuard } from '@app/auth';
import { UploaderService } from './uploader.service';

@UseGuards(JwtAuthGuard)
@Controller('upload')
export class UploaderController {
  constructor(private readonly service: UploaderService) {}

  @Post('file')
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile() file: Express.Multer.File) {
    const res = await this.service.uploadBuffer(file);
    return { code: 200, data: res, message: 'ok' };
  }

  @Post('files')
  @UseInterceptors(FilesInterceptor('files', 10))
  async uploadFiles(@UploadedFiles() files: Express.Multer.File[]) {
    const results = await Promise.all(files.map((f) => this.service.uploadBuffer(f)));
    return { code: 200, data: results, message: 'ok' };
  }
}


